# Maintainer: txtsd <aur.archlinux@ihavea.quest>
# Contributor: Marco Rubin <marco.rubin@protonmail.com>
# Contributor: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: David Runge <dvzrv@archlinux.org>
# Contributor: Panagiotis Mavrogiorgos <pmav99@gmail.com>

pkgname=nuitka
pkgver=2.8.5
pkgrel=1
pkgdesc='Python compiler with full language support and CPython compatibility'
arch=(any)
url='https://nuitka.net'
license=(Apache-2.0)
depends=(
  fuse2
  gdb
  libxml2
  patchelf
  python
  python-appdirs
  python-jinja
  python-ordered-set
  python-pyyaml
  python-setuptools
  python-six
  python-tqdm
  python-zstandard
  scons
)
makedepends=(
  python-build
  python-installer
  python-wheel
)
checkdepends=(
  ccache
  python-boto3
  python-brotli
  strace
)
optdepends=('ccache: for caching builds')
options=(!debug lto)
source=("https://github.com/Nuitka/Nuitka/archive/refs/tags/${pkgver}.tar.gz")
sha256sums=('1b1ba213f224cda3ca4a8fb02d0da85459df964e42d12a3f21f4a56b89011bed')

build() {
  cd ${pkgname^}-${pkgver}

  python -m build --wheel --no-isolation
}

_check() {
  cd ${pkgname^}-${pkgver}

  # Needed to make LTO work with GCC
  export CFLAGS="${CFLAGS} -fuse-linker-plugin -ffat-lto-objects"
  # export LDFLAGS="${LDFLAGS} -fuse-linker-plugin -fno-fat-lto-objects"

  # Catch testing failures early
  echo '==> tests/basics/EmptyModuleTest.py'
  bin/nuitka --module --show-scons --run --report=compilation-report-module.xml --experimental=debug-report-traceback tests/basics/EmptyModuleTest.py
  bin/nuitka --show-scons --run --report=compilation-report-exe.xml --experimental=debug-report-traceback tests/basics/EmptyModuleTest.py

  # Catch testing failures early
  echo '==> data_files/DataFilesMain.py'
  bin/nuitka --show-scons --run --report=compilation-report-exe.xml --experimental=debug-report-traceback tests/plugins/data_files/DataFilesMain.py

  # Check that compilation works
  echo 'print("[x] Can compile main.py to an executable.\n[x] Can run the resulting executable.")' > main.py
  bin/nuitka --output-filename=main --lto=yes --show-scons main.py
  ./main

  # Tests were disabled. See:
  # https://github.com/Nuitka/Nuitka/issues/2595
  # https://github.com/Nuitka/Nuitka/issues/2609
  # https://github.com/Nuitka/Nuitka/issues/3272
  # https://github.com/Nuitka/Nuitka/issues/3284
  ./tests/run-tests --skip-standalone-tests --skip-reflection-test --no-other-python
}

package() {
  cd ${pkgname^}-${pkgver}

  python -m installer --destdir="${pkgdir}" dist/*.whl

  install -vDm644 {Changelog,Developer_Manual,README}.rst -t "${pkgdir}/usr/share/doc/${pkgname}/"
}
